/**
 * 
 */
package com.local.guava.unmodifiable;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;

/**
 * @author admin
 * guava 不可变集合类
 */
public class ImmutableSetMethod {

     //不可变数组
	public static final ImmutableSet<String> COLOR_NAMES = ImmutableSet.of(
			"red",
			"orange",
			"yellow",
			"green",
			"blue",
			"grey",
			"purple");
   //构造一个不可变的map
	public static final ImmutableMap<String,String> CHARACTER = ImmutableMap.of(
			"A",
			"a",
			"C",
			"c",
			"b",
			"B");
	
	//不去掉重复部分
	public void copyOfMethod(List list){
		 ImmutableList<String> imlist=ImmutableList.copyOf(list);
		 System.out.println("first ImmutableList.copyOf()："+imlist);
	}
	
	//有序排序并去掉重复部分
	public void sortedSet_of() {
		ImmutableSortedSet<String> imSortList=ImmutableSortedSet.of("我","爱","爱","爱","你");
        System.out.println("imSortList："+imSortList);
	}
	//尽量用这个
	public void builder() {
		ImmutableSet<Long> imSet =
				ImmutableSet.<Long>builder()
				.add(new Long(12l))
				.add(new Long(15l))
				.build();
		System.out.println("imSortList："+imSet);
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ImmutableSetMethod im = new ImmutableSetMethod();
		System.out.println(COLOR_NAMES);
		System.out.println(CHARACTER);
		
		
		ImmutableList<String> imlist=ImmutableList.copyOf(COLOR_NAMES);//拷贝
		System.out.println(imlist);
		
		//ImmutableSortedSet能进行排序
		ImmutableSortedSet<String> imSortList=ImmutableSortedSet.copyOf(imlist);
		System.out.println(imSortList);
		//能截取自己想要的
		ImmutableList<String> iml=ImmutableList.copyOf(imlist.subList(0, imlist.size()-4));//拷贝
		System.out.println(iml);
		
		List<String> list = new ArrayList<String>();
		System.out.println(list);
		list.add("我");
		list.add("爱");
		list.add("爱");
		list.add("你");
		im.copyOfMethod(list);
		list.add("才怪");
		System.out.println(list);
		im.copyOfMethod(list);
		
		im.sortedSet_of();
		im.builder();
	}

}
